﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Dry.Templates
{
    public class BaseDAL
    {
        public static string GetBaseDAL(string _entLibVersion)
        {
            StringBuilder strBase = new StringBuilder();

            strBase.Append(@"
using System;
using System.Collections.Generic;
using System.Text;
using ¤ProjectName¤.DAL;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.SqlClient;
using System.Data;

namespace ¤ProjectName¤.DAL
{   
    public class BaseDAL
    {
        public static Database GetDatabase()
        {
            return DatabaseFactory.CreateDatabase(""ConnectionString"");
        }
");

            if(_entLibVersion=="5")
            {
                strBase.Append(
                    @"
            public static SqlDataReader AsSqlReader(IDataReader reader)
            {
                return (SqlDataReader) (reader as RefCountingDataReader).InnerReader;
            }");

            }

            strBase.Append(@"

            protected static string TranslateSortType2Sql(string strSortType) {
            if (strSortType.EndsWith(""_DESC""))
                return strSortType.Substring(0, strSortType.Length - 5) + "" DESC"";
            else
                return strSortType.Substring(0, strSortType.Length - 4) + "" ASC"";
        }

        protected static string GetStringFromList(List<int> lstInts)
        {
            string str = """";

            foreach (int intElement in lstInts)
            {
                str += intElement.ToString() + "","";
            }
            str = str.TrimEnd(',');

            return str;
        }

        protected static string GetStringFromList(List<double> lstDoubles)
        {
            string str = """";

            foreach (double intElement in lstDoubles)
            {
                str += intElement.ToString() + "","";
            }
            str = str.TrimEnd(',');

            return str;
        }
    }
}
");

            return strBase.ToString();
        }
    }
}
